import QtQuick
import QtQuick.Window
import QtQuick.Controls

/*
    上方设置光追的仿真参数
    下方按钮，点击后运行光追的算法----算法部分还没完成

    ！！！要设置窗口大小不可改
    ！！！注意带单位

*/

Window {
    id: ray_tracing_window
    width: 400
    height: 500
    maximumHeight: ray_tracing_window.height        // 防止窗口大小发生改变
    maximumWidth: ray_tracing_window.width
    minimumHeight: ray_tracing_window.height
    minimumWidth:ray_tracing_window.width
    title: "ray tracing"
    x: Screen.width/2 - width/2         // 位置--位于屏幕中央
    y: Screen.height/2 - height/2
    
    modality: Qt.WindowModal            // 表示这个窗口没有关闭时，无法点击主窗口

    // Text{
        
    //     anchors.centerIn: parent
    //     text: "This is a window to set parameters about raytracing." 
        
    // }
    Rectangle{
        id: ray_tracing_parameter_rect

        anchors.top: parent.top
        anchors.left: parent.left
        anchors.margins: 5
        anchors.horizontalCenter: parent.horizontalCenter
        

        height: 450
        width: 300

        border.width:1
        border.color: "gray"
        radius: 3

        Column{
            anchors.fill: parent
            spacing:5
            padding:10


            ParaRect{       // 接收器像素长度
                id: pararect_pixel_length
                paraName: "Receiver pixel length"
                paraValue: rayTracingParameter.pixel_length.toFixed(5)
                hasUnit: true
                paraUnit: "m"

                onFinishEdit:{
                    rayTracingParameter.pixel_length = paraValue
                }
            }

            ParaRect{       // 微定日镜长度
                id: pararect_microheliostat_length
                paraName: "Microheliostat length"
                paraValue: rayTracingParameter.microheliostat_length.toFixed(5)
                hasUnit: true
                paraUnit: "m"

                onFinishEdit:{
                    rayTracingParameter.microheliostat_length = paraValue
                }
            }

            ParaRect{       // num_sunshape_groups
                id: pararect_num_sunshape_groups
                paraName: "num sunshape groups"
                paraValue: rayTracingParameter.num_sunshape_groups

                onFinishEdit:{
                    rayTracingParameter.num_sunshape_groups = paraValue
                }
            }

            ParaRect{       // num_sunshape_lights_per_group
                id: pararect_num_sunshape_lights_per_group
                paraName: "num sunshape lights per group"
                paraValue: rayTracingParameter.num_sunshape_lights_per_group

                onFinishEdit:{
                    rayTracingParameter.num_sunshape_lights_per_group = paraValue
                }
            }

            ParaRect{       // inverse_transform_sampling_groups
                id: pararect_inverse_transform_sampling_groups
                paraName: "inverse transform sampling groups"
                paraValue: rayTracingParameter.inverse_transform_sampling_groups

                onFinishEdit:{
                    rayTracingParameter.inverse_transform_sampling_groups = paraValue
                }
            }

            ParaRect{       // 整个场景的长度
                id: pararect_ground_length
                paraName: "ground length"
                paraValue: rayTracingParameter.ground_length.toFixed(5)
                hasUnit: true
                paraUnit: "m"

                onFinishEdit:{
                    rayTracingParameter.ground_length = paraValue
                }
            }

            ParaRect{       // 整个场景的宽度
                id: pararect_ground_width
                paraName: "ground width"
                paraValue: rayTracingParameter.ground_width.toFixed(5)
                hasUnit: true
                paraUnit: "m"

                onFinishEdit:{
                    rayTracingParameter.ground_width = paraValue
                }
            }

            ParaRect{       // 网格范围大小--x
                id: pararect_grid_sizex
                paraName: "grid size"
                paraValue: rayTracingParameter.grid_size_x.toFixed(5)
                hasIdentity: true
                paraIdentity: "x:"
                hasUnit: true
                paraUnit: "m"

                onFinishEdit:{
                    rayTracingParameter.grid_size_x = paraValue
                }
            }

            ParaRect{       // 网格范围大小--y
                id: pararect_grid_sizey
                hasName: false
                paraValue: rayTracingParameter.grid_size_y.toFixed(5)
                hasIdentity: true
                paraIdentity: "y:"
                hasUnit: true
                paraUnit: "m"

                onFinishEdit:{
                    rayTracingParameter.grid_size_y = paraValue
                }
            }

            ParaRect{       // 网格范围大小--z
                id: pararect_grid_sizez
                hasName: false
                paraValue: rayTracingParameter.grid_size_z.toFixed(5)
                hasIdentity: true
                paraIdentity: "z:"
                hasUnit: true
                paraUnit: "m"

                onFinishEdit:{
                    rayTracingParameter.grid_size_z = paraValue
                }
            }

            ParaRect{       // 网格位置--x
                id: pararect_grid_posx
                paraName: "grid pos"
                paraValue: rayTracingParameter.grid_pos_x.toFixed(5)
                hasIdentity: true
                paraIdentity: "x:"
                hasUnit: true
                paraUnit: "m"

                onFinishEdit:{
                    rayTracingParameter.grid_pos_x = paraValue
                }
            }

            ParaRect{       // 网格位置--y
                id: pararect_grid_posy
                hasName: false
                paraValue: rayTracingParameter.grid_pos_y.toFixed(5)
                hasIdentity: true
                paraIdentity: "y:"
                hasUnit: true
                paraUnit: "m"

                onFinishEdit:{
                    rayTracingParameter.grid_pos_y = paraValue
                }
            }

            ParaRect{       // 网格位置--z
                id: pararect_grid_posz
                hasName: false
                paraValue: rayTracingParameter.grid_pos_z.toFixed(5)
                hasIdentity: true
                paraIdentity: "z:"
                hasUnit: true
                paraUnit: "m"

                onFinishEdit:{
                    rayTracingParameter.grid_pos_z = paraValue
                }
            }

            ParaRect{       // 网格间隔--x--即小格子的大小
                id: pararect_grid_intervalx
                paraName: "grid interval"
                paraValue: rayTracingParameter.grid_interval_x.toFixed(5)
                hasIdentity: true
                paraIdentity: "x:"
                hasUnit: true
                paraUnit: "m"

                onFinishEdit:{
                    rayTracingParameter.grid_interval_x = paraValue
                }
            }

            ParaRect{       // 网格间隔--y--即小格子的大小
                id: pararect_grid_intervaly
                hasName: false
                paraValue: rayTracingParameter.grid_interval_y.toFixed(5)
                hasIdentity: true
                paraIdentity: "y:"
                hasUnit: true
                paraUnit: "m"

                onFinishEdit:{
                    rayTracingParameter.grid_interval_y = paraValue
                }
            }

            ParaRect{       // 网格间隔--z--即小格子的大小
                id: pararect_grid_intervalz
                hasName: false
                paraValue: rayTracingParameter.grid_interval_z.toFixed(5)
                hasIdentity: true
                paraIdentity: "z:"
                hasUnit: true
                paraUnit: "m"

                onFinishEdit:{
                    rayTracingParameter.grid_interval_z = paraValue
                }
            }


        }
            
        Connections {       // 建立一个到NOTIFY接口的连接，这里，似乎没什么用，可以先留着
            target:rayTracingParameter
            // onRayCntChanged: {    }
            onPixelLengthChanged:{  pararect_pixel_length.paraValue = rayTracingParameter.pixel_length.toFixed(5)}
            onMicroheliostatLengthChanged:{ pararect_microheliostat_length.paraValue = rayTracingParameter.microheliostat_length.toFixed(5)}

            onNumSunshapeGroupsChanged:{ pararect_num_sunshape_groups.paraValue = rayTracingParameter.num_sunshape_groups }
            onNumSunshapeLightsPerGroupChanged:{ pararect_num_sunshape_lights_per_group.paraValue = rayTracingParameter.num_sunshape_lights_per_group}
            onInverseTransformSamplingGroupsChanged:{ pararect_inverse_transform_sampling_groups.paraValue = rayTracingParameter.inverse_transform_sampling_groups}

            onGroundLengthChanged:{ pararect_ground_length.paraValue = rayTracingParameter.ground_length}
            onGroundWidthChanged:{ pararect_ground_width.paraValue = rayTracingParameter.ground_width}

            onGridSizeXChanged:{ pararect_grid_sizex.paraValue = rayTracingParameter.grid_size_x }
            onGridSizeYChanged:{ pararect_grid_sizey.paraValue = rayTracingParameter.grid_size_y }
            onGridSizeZChanged:{ pararect_grid_sizez.paraValue = rayTracingParameter.grid_size_z }
            onGridPosXChanged:{ pararect_grid_posx.paraValue = rayTracingParameter.grid_pos_x }
            onGridPosYChanged:{ pararect_grid_posy.paraValue = rayTracingParameter.grid_pos_y }
            onGridPosZChanged:{ pararect_grid_posz.paraValue = rayTracingParameter.grid_pos_z }
            onGridIntervalXChanged:{ pararect_grid_intervalx.paraValue = rayTracingParameter.grid_interval_x }
            onGridIntervalYChanged:{ pararect_grid_intervaly.paraValue = rayTracingParameter.grid_interval_y }
            onGridIntervalZChanged:{ pararect_grid_intervalz.paraValue = rayTracingParameter.grid_interval_z }
        }

    }

    /*
        这里按下按钮，应该是执行光追过程，算法目前还没集成...
    */
    Button{
        anchors.top: ray_tracing_parameter_rect.bottom
        anchors.margins: 10
        anchors.horizontalCenter: parent.horizontalCenter
        
        text: "Run Ray Tracing"

        onClicked:{
            console.log("执行ray tracing！！！")
            algorithmProcessor.runRayTracing();
        }
    }

}